//
//  SliderCell.m
//  HotWord
//
//  Created by 贺 欢 on 13-3-17.
//
//

#import "SliderCell.h"
#import "MessageManager.h"

@interface SliderCell ()
@property (retain, nonatomic) IBOutlet UILabel *titleLabel;
@property (retain, nonatomic) IBOutlet UILabel *messageCountLabel;



@end

@implementation SliderCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)dealloc
{
    [_titleLabel release];
    [_messageCountLabel release];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:NOTIFICATION_RECEIVE_MESSAGE object:nil];
    [super dealloc];
}

- (void)setTitleWithIndex:(NSUInteger)index
{
    _titleLabel.text = [SLIDER_BAR_OPTIONS objectAtIndex:index];
    if (index == _optionType)
    {
        _titleLabel.textColor = RGBCOLOR(255, 150, 0);
    }
    else
    {
        _titleLabel.textColor = RGBCOLOR(255, 255, 255);
    }
    
    _messageCountLabel.hidden = YES;
    [[NSNotificationCenter defaultCenter] removeObserver:self];

    if (index == 2)
    {
        [self receiveMessageNotification];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveMessageNotification) name:NOTIFICATION_RECEIVE_MESSAGE object:nil];
    }
}

- (void)receiveMessageNotification
{
    if ([MessageManager sharedManager].newMessageCount > 0)
    {
        _messageCountLabel.hidden = NO;
        _messageCountLabel.text = [NSString stringWithFormat:@"+%d",[MessageManager sharedManager].newMessageCount];
    }
    else
    {
        _messageCountLabel.hidden = YES;
    }
}


@end
